package com.vankimgps.activity;

import java.util.List;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.vankimgps.database.DatabaseHelper;
import com.vankimgps.listvehicles.ListVehiclesActivity;
import com.vankimgps.models.ResponseVehicles;
import com.vankimgps.models.Vehicles;
import com.vankimgps.services.ServiceListener;
import com.vankimgps.services.Services;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;

public class TrackingActivity extends Activity implements
ServiceListener {
	private String token;
	private String userID;
	private GoogleMap mMap;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.tracking_layout);
		
	    DatabaseHelper db = new DatabaseHelper(this);
	    token = db.getToken();
	    userID = db.getUserID();
	    
	    Button btnVehicle = (Button)findViewById(R.id.btnVehicle);
	    btnVehicle.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				updateVehicles();
			}
		});
//	    mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
	}
	
	void updateVehicles(){
		Services service = new Services(this);
		Log.i("VANKIM","VAN KIM Token + UserID: " + token + "   " + userID);
		service.getVehicles(token, userID);
	}
	
	@Override
	public void onCompleted(Services service, Object result) {
		ResponseVehicles response = (ResponseVehicles)result;
		int code = response.getCode();
		Log.i("VANKIM","VANKIM code = " + code);
		Log.i("VANKIM","VANKIM msg = " + response.getMsg());
		
		List<Vehicles> lstVehicles = response.getList();
		for (int i=0; i < lstVehicles.size();i++){
			Vehicles veh = lstVehicles.get(i);
			Log.i("VANKIM","VANKIM VehicleNo = " + veh.getVehNoF());			
		}
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
	    switch(item.getItemId())
	    {
	    case R.id.menu_finding:{
			Intent intent = new Intent(this,FindingActivity.class);				
			startActivity(intent);
			finish();
	    }
	        break;
	    case R.id.menu_settings:{
			Intent intent = new Intent(this,SettingsActivity.class);				
			startActivity(intent);
			finish();
	    }
	        break;
	    case R.id.menu_aboutus:{
			Intent intent = new Intent(this,ListVehiclesActivity.class);				
			startActivity(intent);
//			finish();
	    }
	        break;
	    }
	    return true;
	}
}